package com.wehealth.adapter;


import java.util.List;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.wehealth.R;
import com.wehealth.dm.Doctor;
import com.wehealth.util.Common;
import com.wehealth.util.GetUrl;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
/**
 * 咨询医生列表
 * @author BCAPP
 *
 */
public class DrListAdapter extends BaseAdapter {
	/**
	 * 上下文
	 */
	private Context ctx;
	/**
	 * 列表数据
	 */
	private List<Doctor> dr_list;
	
	public DrListAdapter(Context ctx,List<Doctor> dr_list){
		this.ctx = ctx;
		this.dr_list = dr_list;
	}

	@Override
	public int getCount() {
		return dr_list.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int arg0, View convertView, ViewGroup arg2) {
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			//转化控件
			convertView = LayoutInflater.from(ctx).inflate(R.layout.dr_list_item,null);
			//id
			holder.id = (TextView)convertView.findViewById(R.id.dr_id);
			//名称
			holder.name = (TextView)convertView.findViewById(R.id.dr_name);
			holder.icons = (ImageView)convertView.findViewById(R.id.dr_icons);
			holder.post = (TextView)convertView.findViewById(R.id.dr_post);
			holder.desc = (TextView)convertView.findViewById(R.id.dr_desc);
			
			convertView.setTag(holder);
		}else {
			holder = (ViewHolder) convertView.getTag();
		}
		//赋值
		holder.id.setText(dr_list.get(arg0).getID()+"");
		holder.name.setText(dr_list.get(arg0).getRealName());
		holder.post.setText(dr_list.get(arg0).getLevel());
		holder.desc.setText(dr_list.get(arg0).getIntro());
		
		ImageLoader.getInstance().displayImage(GetUrl.hostUrl+dr_list.get(arg0).getPhoto(), holder.icons,Common.options);
		
		return convertView;
	}
	// adapter所需字段
	public final class ViewHolder {
		// 医生id
		public TextView id;
		// 医生名字
		public TextView name;
		// 医生头像
		public ImageView icons;
		// 医生职位
		public TextView post;
		// 医生描述
		public TextView desc;
		
	}
}
